package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.model.City;

@Repository
public class CityDao extends HibernateDao<City>{

	public List getCities() {
		String hql = "select c.id,c.cityName "
				+ "from City as c";
		Query q = getCurrentSession().createQuery(hql);
		return q.list();
	}

	public List getPassengerStation(int cityId) {
		String hql = "select c.passengerStationList "
				+ "from City as c "
				+ "where c.id = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, cityId);
		return q.list();
	}

	public List getSites(int cityId) {
		String hql = "select c.siteList "
				+ "from City as c "
				+ "where c.id = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, cityId);
		return q.list();
	}

	public void addCity(String cityName) {
		City city = new City();
		city.setCityName(cityName);
		this.save(city);
	}

	public void editCity(int cityId, String cityName) {
		City city = this.get(cityId);
		city.setCityName(cityName);
		this.update(city);
	}

	public void deleteCity(int cityId) {
		this.delete(get(cityId));
	}

}
